package com.bootcamp.mall.listener;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.util.ArrayList;
import java.util.List;

@WebListener
public class ApplicationListener implements ServletContextListener, HttpSessionListener, HttpSessionAttributeListener {

    public ApplicationListener() {
    }

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        /* This method is called when the servlet context is initialized(when the Web application is deployed). */
        List<String> mallAuths = new ArrayList<String>();
        // 判断当前是否为 data,updatePwd,updateUserData,getOrderByState,settleAccounts,confirmReceive,pay,addOrder,deleteOrder,askGoodMsg,sendComment
        mallAuths.add("user/data");
        mallAuths.add("user/updatePwd");
        mallAuths.add("user/updateUserData");
        mallAuths.add("order/getOrderByState");
        mallAuths.add("order/settleAccounts");
        mallAuths.add("order/confirmReceive");
        mallAuths.add("order/pay");
        mallAuths.add("order/addOrder");
        mallAuths.add("order/deleteOrder");
        mallAuths.add("order/askGoodMsg");
        mallAuths.add("order/sendComment");
        ServletContext context = sce.getServletContext();
        context.setAttribute("mallAuth",mallAuths);
        context.setAttribute("origin","http://192.168.4.34:8080");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        /* This method is called when the servlet Context is undeployed or Application Server shuts down. */
    }

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        /* Session is created. */
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        /* Session is destroyed. */
    }

    @Override
    public void attributeAdded(HttpSessionBindingEvent sbe) {
        /* This method is called when an attribute is added to a session. */
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent sbe) {
        /* This method is called when an attribute is removed from a session. */
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent sbe) {
        /* This method is called when an attribute is replaced in a session. */
    }
}
